package org.example.web.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.annotation.MyLog;
import org.example.web.domain.Emp;
import org.example.web.domain.QueryPage;
import org.example.web.mapper.EmpMapper;
import org.example.web.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public QueryPage pageQuery(String name, Integer gender, Date begin, Date end, int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Emp> emps = empMapper.pageQuery(name,gender,begin,end);
        Page<Emp> pageEmp = (Page<Emp>) emps;
        return new QueryPage(pageEmp.getTotal(),pageEmp.getResult());
    }

    @MyLog
    @Override
    public void deleteById(List ids) {
        empMapper.deleteById(ids);
    }

    @MyLog
    @Override
    public void add(Emp emp) {
        emp.setCreateTime(new Date());
        emp.setUpdateTime(new Date());
        empMapper.add(emp);
    }

    @Override
    public Emp getById(Long id) {
        return empMapper.getById(id);
    }

    @Override
    @MyLog
    public void update(Emp emp) {
        emp.setUpdateTime(new Date());
        empMapper.update(emp);
    }

    @Override
    public Emp getUserByUserNameAndPassword(Emp emp) {
        return empMapper.getUserByUserNameAndPassword(emp);
    }
}
